<template>
	<view class="scrollPage">
			<u-navbar :border-bottom="false" title="邀请用户" back-icon-color="#ffffff" :background="{background:'#2149c3'}" title-color="#ffffff"></u-navbar>
			<view class="view_bg"></view>
			<view class="ewm_box">
				<view class="t1">我的专属二维码</view>
				<view class="img1">
					<u-image width="330rpx" height="330rpx" :src="wxaImg"></u-image>
				</view>
				<view class="t1">
					<view>全球第一个人人都能赚钱的装修众销平台，</view>
					<view>邀请越多赚钱越多！</view>
				</view>
			</view>
			<view class="view_btn">
				<view class="v1_btn1">
					<u-button  open-type="share" size="medium" shape="circle" :custom-style="{background:'#ffcd91',color:'#ffffff',width:'100%'}">邀请用户</u-button>
				</view>
				<view class="v1_btn1">
					<u-button @click="showImgs" size="medium" shape="circle" :custom-style="{background:'#ffcd91',color:'#ffffff',width:'100%'}">保存我的推广码</u-button>
				</view>
				<view class="v1_btn1">
					<u-button size="medium" shape="circle" :custom-style="{background:'#ffffff',color:'#ffcd91',width:'100%'}">查看我的团队</u-button>
				</view>
				
			</view>
			<!-- <view class="padding flex flex-direction">
				<button class="cu-btn bg-green margin-tb-sm lg" open-type="share">邀请用户</button>
			</view>
			<view class="padding flex flex-direction">
				<button class="cu-btn bg-blue margin-tb-sm lg" @click="ewmShare()">小程序码分享</button>
			</view> -->
			<!-- <view v-if="ewmShow" class="flex solid-bottom padding justify-center">
				<image @click="showImgs" style="width:430rpx;height: 430rpx;" :src="wxaImg"></image>
			</view> -->
		</view>
	
			
	
</template>

<script>
var _self;
	import {
		mapState,
		mapMutations
	} from 'vuex';	
	export default {
		computed: {
			...mapState(['userInfo', 'hasLogin', 'loginProvider', 'openid'])
		},
	    data() {
	        return {
				ewmShow:false,
				atoken:"",
				wxaImg: ''
	        }
	    },
		onLoad() {
			_self = this;
			_self.ewmShare();
		},
		onShareAppMessage(res) {
		      return {
		        title: '邀请您进入（装修众销平台）',
		        path: '/pages/index/index?scene='+_self.userInfo.id,
				imageUrl: '/static/bg.png',
		      }
		},
	    methods:{
			...mapMutations(['login', 'logout', 'setOpenid', 'setProvider']),
	        ewmShare(){
				uni.request({
					url: _self.serverUrl + 'app/getAsData',
					header: {
						"content-type": "application/x-www-form-urlencoded; charset=UTF-8"
					},
					method: 'POST',
					data: {
					},
					success: (r) => {
						//console.log(r.data.data);
						if (r.data.code == 0) {
							uni.request({
								url: _self.serverUrl + 'app/sendUrl',
								header: {
									"content-type": "application/x-www-form-urlencoded; charset=UTF-8"
								},
								data: {
									url:'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='+r.data.data.appid+'&secret='+r.data.data.secret
								},
								method: 'POST',
								success(res) {
									if(res.data.code==0){
										_self.atoken = JSON.parse(res.data.data).access_token;
										//console.log(_self.atoken);
										_self.getWxa();
									}
								}
							});
						}
					}
				})
			},
			getWxa(){
				var data = {
					"scene":_self.userInfo.id
				}
				uni.request({
					url: _self.serverUrl + 'app/sendUrl',
					header: {
						"content-type": "application/x-www-form-urlencoded; charset=UTF-8"
					},
					data: {
						url:'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='+_self.atoken,
						params:JSON.stringify(data),
						method:'post',
						responseType:'arraybuffer'
					},
					method: 'POST',
					success(res) {
						if(res.data.code==0){
							// console.log(res);
							_self.wxaImg = _self.serverUrl+res.data.data;
							_self.ewmShow = true;
						}
					}
				});
			},
			// 预览图片
			showImgs(){
				uni.previewImage({
					urls: [_self.wxaImg],
					current:0
				});
			}
		}
	}	
</script>

<style lang="less">
	.view_bg{
		height: 300rpx;
		background-color: #2149c3;
	}
	.ewm_box{
		width: 90%;
		height: 710rpx;
		background-image: linear-gradient(0deg, 
			#ffcc8e 0%, 
			#f8cb96 100%), 
		linear-gradient(
			#2149c3, 
			#2149c3);
		background-blend-mode: normal, 
			normal;
		box-shadow: 0px 0px 23rpx 2rpx 
			rgba(194, 132, 58, 0.5);
		border-radius: 14rpx;
		margin:-280rpx auto 0rpx;
		box-sizing:border-box;
		padding: 30rpx;
	}
	.ewm_box{
		.t1{
			font-size: 29rpx;
			line-height: 36rpx;
			color: #8e5f26;
		}
		.img1{
			height: 500rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
	.view_btn{
		padding: 50rpx 60rpx;
		.v1_btn1{
			margin-bottom: 30rpx;
		}
	}
</style>
